﻿#ifndef REGISTERINFO_H
#define REGISTERINFO_H

#include <qobject.h>
#include <qtimer.h>
#include <qvector.h>

class Device : public QObject
{
  Q_OBJECT
private:
  static const uchar mask_turnTable_runningState_targetPosition=0x01;
  static const uchar mask_turnTable_runningState_targetRate=0x02;
  static const uchar mask_turnTable_runningState_targetStop=0x04;
  static const uchar mask_turnTable_runningState_power=0x08;
  static const uchar mask_turnTable_runningState_circuit=0x10;
  static const uchar mask_turnTable_runningState_amplifier=0x20;
  static const uchar mask_turnTable_runningState_running=0x40;
  static const uchar mask_turnTable_runningMode=0x80;
private://property
  uint deviceId=0;
  uint hostAddress=0;
  ushort port = 0;
  float turnTable_currentPosition=0;
  float turnTable_currentRate=0;
  float turnTable_targetPosition=0;
  float turnTable_targetRate=0;
  float turnTable_targetAcceleration=0;
  uchar turnTable_runningState=0;//将running Mode整合到runningState中去，在最高位0代表位置模式，1代表速率模式
  float turnTable_thermostat_currentTemperature=0;
  float turnTable_thermostat_targetTemperature=0;
  float turnTable_thermostat_targetTemperatureRate=0;
private:
  QTimer timer_life;
  static const int byteArraySize=4*12;//property的数量 × 4
public:
  explicit Device();
  Device(const Device& device);
  virtual ~Device();
  Device &operator=(const Device &device);
signals:
  void signal_lifeTimeOut(Device* device);
public:
  bool isValid();
public://to and from binary
  QByteArray toByteArray() const;
  static Device fromByteArray(QByteArray data,bool*isOK=Q_NULLPTR);
  static QVector<Device> fromByteArrays(QByteArray data,bool*isOK=Q_NULLPTR);
private://to and from binary
  static bool fromByteArray(Device* device,char* srcData,int srcSize,int* offset=Q_NULLPTR);
public://geter and seter
  uint getDeviceId();
  Device* setDeviceId(const uint deviceId);
  uint getHostAddress();
  Device* setHostAddress(const uint hostAddress);
  ushort getPort();
  Device* setPort(const ushort port);
  int getLifeTime_s() const;
  Device* setLifeTime_s(const int lifeTime);
  int getLifeTime_ms() const;
  Device* setLifeTime_ms(const int lifeTime);
  float getTurnTable_currentPosition();
  Device* setTurnTable_currentPosition(float turnTable_currentPosition);
  float getTurnTable_currentRate();
  Device* setTurnTable_currentRate(float turnTable_currentRate);
  float getTurnTable_targetPosition();
  Device* setTurnTable_targetPosition(float turnTable_targetPosition);
  float getTurnTable_targetRate();
  Device* setTurnTable_targetRate(float turnTable_targetRate);
  float getTurnTable_targetAcceleration();
  Device* setTurnTable_targetAcceleration(float turnTable_targetAcceleration);
  uchar getTurnTable_runningState();
  Device* setTurnTable_runningState(uchar turnTable_runningState);
  bool getTurnTable_runningState_targetPosition();
  Device* setTurnTable_runningState_targetPosition(bool turnTable_runningState_targetPosition);
  bool getTurnTable_runningState_targetRate();
  Device* setTurnTable_runningState_targetRate(bool turnTable_runningState_targetRate);
  bool getTurnTable_runningState_targetStop();
  Device* setTurnTable_runningState_targetStop(bool turnTable_runningState_targetStop);
  bool getTurnTable_runningState_power();
  Device* setTurnTable_runningState_power(bool turnTable_runningState_power);
  bool getTurnTable_runningState_circuit();
  Device* setTurnTable_runningState_circuit(bool turnTable_runningState_circuit);
  bool getTurnTable_runningState_amplifier();
  Device* setTurnTable_runningState_amplifier(bool turnTable_runningState_amplifier);
  bool getTurnTable_runningState_running();
  Device* setTurnTable_runningState_running(bool turnTable_runningState_running);
  bool getTurnTable_runningMode();//返回true代表速率模式，false代表位置模式
  Device* setTurnTable_runningMode(bool turnTable_runningMod);
  float getTurnTable_thermostat_currentTemperature();
  Device* setTurnTable_thermostat_currentTemperature(float turnTable_thermostat_currentTemperature);
  float getTurnTable_thermostat_targetTemperature();
  Device* setTurnTable_thermostat_targetTemperature(float turnTable_thermostat_targetTemperature);
  float getTurnTable_thermostat_targetTemperatureRate();
  Device* setTurnTable_thermostat_targetTemperatureRate(float turnTable_thermostat_targetTemperatureRate);
};

#endif // REGISTERINFO_H
